package org.zxxxt.shortlink.admin.controller;


import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.zxxxt.shortlink.admin.common.convention.result.Result;
import org.zxxxt.shortlink.admin.common.convention.result.Results;
import org.zxxxt.shortlink.admin.dto.req.GroupSaveReqDTO;
import org.zxxxt.shortlink.admin.dto.req.GroupSortReqDTO;
import org.zxxxt.shortlink.admin.dto.req.GroupUpdateReqDTO;
import org.zxxxt.shortlink.admin.dto.resp.GroupRespDTO;
import org.zxxxt.shortlink.admin.service.GroupService;

import java.util.List;


@RequiredArgsConstructor
@RestController
public class GroupController {

    private final GroupService groupService;


    /**
     * 新增分组
     */
    @PostMapping("/api/short-link/admin/v1/group")
    public Result<Void> save(@RequestBody GroupSaveReqDTO requestParam){
        groupService.saveGroup(requestParam.getName());
        return Results.success();
    }

    /**
     * 查询分组
     */
    @GetMapping("/api/short-link/admin/v1/group")
    public Result<List<GroupRespDTO>> listGroup(){
        return Results.success(groupService.listGroup());
    }

    /**
     * 修改分组
     */
    @PutMapping("/api/short-link/admin/v1/group")
    public Result<Void> updateGroup(@RequestBody GroupUpdateReqDTO requestParam){
        groupService.updateGroup(requestParam);
        return Results.success();
    }

    /**
     * 删除分组
     */
    @DeleteMapping("/api/short-link/admin/v1/group")
    public Result<Void> deleteGroup(@RequestParam("gid") String gid){
        groupService.deleteGroup(gid);
        return Results.success();
    }


    /**
     * 分组排序
     */
    @PostMapping("/api/short-link/admin/v1/group/sort")
    public Result<Void> sortGroup(@RequestBody List<GroupSortReqDTO> requestParam){
        groupService.sortGrooup(requestParam);
        return  Results.success();
    }

}
